﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace TestWork2
{
    class OneDimensionalArray
    {
        private int[] array;

        public int[] MyArray(int arraySize)
        {
            array = new int[arraySize];
            //Random rnd = new Random();
            for (int i = 0; i < arraySize; i++)
            {
                //array[i] = rnd.Next(1, 10);
                array[i] = Int32.Parse(Console.ReadLine());
            }
            return array;
        }

        public int this[int index]
        {
            get
            {
                return array[index];
            }
            set
            {
                if (array[index] > array.Length || array[index] < 0)
                {
                    Console.WriteLine("ERROR");
                }
                else
                {
                    array[index] = value;
                }
            }
        }

        public int[] SummArrays(int[] firstArray, int[] secondArray)
        {
            int[] resultArray = new int[firstArray.Length];
            //foreach (var arr1 in firstArray)
            //{
            //    Console.Write(arr1);
            //}
            //Console.WriteLine();
            //foreach (var arr2 in secondArray)
            //{
            //    Console.Write(arr2);
            //}
            //Console.WriteLine();
            if (firstArray.Length == secondArray.Length)
            {
                for (int i = 0; i < firstArray.Length; i++)
                {
                    resultArray[i] = firstArray[i] + secondArray[i];
                }
            }
            else
            {
                Console.WriteLine("Arrays should be the same length");
            }
            return resultArray;
        }

        public int[] SubArrays(int[] firstArray, int[] secondArray)
        {
            int[] resultArray = new int[firstArray.Length];
            //foreach (var arr1 in firstArray)
            //{
            //    Console.Write(arr1);
            //}
            //Console.WriteLine();
            //foreach (var arr2 in secondArray)
            //{
            //    Console.Write(arr2);
            //}
            //Console.WriteLine();
            if (firstArray.Length == secondArray.Length)
            {
                for (int i = 0; i < firstArray.Length; i++)
                {
                    resultArray[i] = firstArray[i] - secondArray[i];
                }
            }
            else
            {
                Console.WriteLine("Arrays should be the same length");
            }
            return resultArray;
        }
    }
}
